package thread.sync4;

public class Boo {
    public synchronized void methodA(){//方法synchronized就是指代this
        Thread t=Thread.currentThread();
        System.out.println(t.getName()+":正在执行A方法");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
        }
        System.out.println(t.getName()+":A方法执行完毕");
    }

    public void methodB(){
        synchronized (this) {//同步监视器对象this
            Thread t=Thread.currentThread();
            System.out.println(t.getName()+":正在执行B方法");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
            System.out.println(t.getName()+":B方法执行完毕");
        }
    }
}
